import { Route, Redirect } from 'react-router-dom'
import { isAuth } from '@/utils'

export const AuthRoute = ({ component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) => {
        if (!isAuth()) {
          return (
            <Redirect
              to={{
                pathname: '/login',
                state: { from: props.location.pathname },
              }}
            ></Redirect>
          )
        }
        return <Component />
      }}
    ></Route>
  )
}
